//
//  BottomListViewController.swift
//  CHSimpleUI
//
//  Created by cyptt on 2024/4/22.
//

import UIKit

class BottomListViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

       
        self.view.backgroundColor = UIColor.white
        
        self.view.addSubview(self.buttonList)
        
        
     
        self.buttonList.snp.makeConstraints { make in
            make.left.equalTo(0)
            make.right.equalTo(0)
            make.height.equalTo(50)
            make.top.equalTo(200)
        }
        
        
        self.buttonList.dataSource = ["001","002","003"]
        self.buttonList.reloadData()
        
      
    
    
        self.buttonList.refreshItemUI { btns in
            
            btns.forEach { btn  in
                (btn as UIButton).backgroundColor = UIColor.red
                btn.layer.cornerRadius = 10
                btn.layer.masksToBounds = true
            }
        }
        
        self.buttonList.btnClickFun { index, title in
            print(title)
            print(index)
        }
      
    }
    
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        
//        self.buttonList.dataSource = ["wo","ni","ta","i"]
        self.buttonList.refreshData(dataArr: ["wo","ni","ta","i"])
//        self.buttonList.reloadData()
       
        self.buttonList.refreshItemUI { btns in
            btns.forEach { btn  in
                (btn as UIButton).backgroundColor = UIColor.red
                btn.layer.cornerRadius = 10
                btn.layer.masksToBounds = true
            }
        }
    }

   
    lazy var buttonList = {()-> CHSimpleBtnListView in
     
        let view:CHSimpleBtnListView = CHSimpleBtnListView()
        view.itemSize = CGSize.init(width: 76, height: 30)
        view.isEdging = false
        view.minimumInteritemSpacing =  10
        
        view.backgroundColor = UIColor.gray

        return view
    }()

}
